package com.tenqian.utils;


import com.tenqian.Result;
import com.tenqian.enums.ResultEnum;

/**
 * Created by Administrator on 2017/7/18.
 */
public class ResultUtil {
    /**
     * 共通方法：成功的情况
     *
     * @return
     */
    public static Result success(Object object) {
        Result result = new Result();
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMsg(ResultEnum.SUCCESS.getMsg());
        result.setData(object);
        return result;
    }

    /**
     * 共通方法：成功的情况，data是null
     *
     * @return
     */
    public static Result success() {
        return success(null);
    }

    /**
     * 返回错误结果
     *
     * @param resultEnum
     * @return
     */
    public static Result error(ResultEnum resultEnum) {
        Result result = new Result();
        result.setCode(resultEnum.getCode());
        result.setMsg(resultEnum.getMsg());
        return result;
    }

    /**
     * 异常的结果
     *
     * @param e
     * @return
     */
    public static Result error(Exception e) {
        Result result = new Result();
        result.setCode(-2);
        result.setMsg(e.getMessage());
        return result;
    }
}
